package cn.zhz.privacy.sensitive.handler;

import cn.hutool.core.util.StrUtil;
import cn.zhz.privacy.sensitive.SensitiveType;
import cn.zhz.privacy.sensitive.SensitiveTypeHandler;

/**
 * 座机信息脱敏
 * 座机的前2位和后4位保留，其余的隐藏。
 * @author chenhaiyang
 */
public class FixedPhoneSensitiveHandler implements SensitiveTypeHandler {
    @Override
    public SensitiveType getSensitiveType() {
        return SensitiveType.FIXED_PHONE;
    }

    @Override
    public String handle(Object src) {
        if(src==null){
            return null;
        }
        String fixedPhone=src.toString();
        int len=fixedPhone.length();
        if(len<8){
            return fixedPhone;
        }
        return StrUtil.padPre(StrUtil.subPre(fixedPhone, 2),len-6,"*")
                .concat(StrUtil.subSufByLength(fixedPhone, 4));
    }
}
